package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.NotEnoughFundsException;

@SuppressWarnings("serial")
public class SavingsAccount extends AbstractAccount {
	
	public SavingsAccount() throws IllegalArgumentException {
		super(0);
	}
	
    public SavingsAccount(double balance) throws IllegalArgumentException
	{
		super(balance);
	}
	
	@Override
	public String toString() {
		return "SavingsAccount [balance=" + getBalance() + "]";
	}	
	
	@Override
	public void deposit(double x) 
	{
		setBalance(getBalance() + x);
	}
	
	@Override
	public void withdraw(double x) throws NotEnoughFundsException
	{
		if (getBalance() >= x) 
		{
			setBalance(getBalance() - x);
		} 
		else 
		{
			throw new NotEnoughFundsException(x - getBalance());
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return getBalance();
	}

}
